/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utilidades;

import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

/**
 *
 * @author humberto
 */
public class resaltadores {
    
    public static class resaltadorString implements KeyListener
    {
        private JTextField campo;
        
        public resaltadorString (JTextField campo)
        {
            this.campo = campo;
        }

            public void keyTyped(KeyEvent e) {
                if (utils.verificarString(campo.getText()))
                    campo.setForeground(new Color(0,150,0));
                else
                    campo.setForeground(Color.red);
            }

            public void keyPressed(KeyEvent e) {
                if (utils.verificarString(campo.getText()))
                    campo.setForeground(new Color(0,150,0));
                else
                    campo.setForeground(Color.red);
            }

            public void keyReleased(KeyEvent e) {
                if (utils.verificarString(campo.getText()))
                    campo.setForeground(new Color(0,150,0));
                else
                    campo.setForeground(Color.red);
            }

    }
     
    
    public static class resaltadorInteger implements KeyListener
    {
        JTextField campo;
        public resaltadorInteger (JTextField campo)
        {
            this.campo = campo;
        }

            public void keyTyped(KeyEvent e) {
                if (utils.verificarInteger(campo.getText()))
                    campo.setForeground(new Color(0,150,0));
                else
                    campo.setForeground(Color.red);
            }

            public void keyPressed(KeyEvent e) {
                if (utils.verificarInteger(campo.getText()))
                    campo.setForeground(new Color(0,150,0));
                else
                    campo.setForeground(Color.red);
            }

            public void keyReleased(KeyEvent e) {
                if (utils.verificarInteger(campo.getText()))
                    campo.setForeground(new Color(0,150,0));
                else
                    campo.setForeground(Color.red);
            }

    }

    
    
    public static class enfocador implements FocusListener
    {
        JTextField campo;
        boolean integerOstring;
        public enfocador (JTextField campo, boolean tipo)
        {
            this.campo = campo;
            integerOstring = tipo;
        }
        public void focusGained(FocusEvent e)
        {
            campo.setBackground(Color.white);
           if (utils.verificarInteger(campo.getText()) && !integerOstring )
                campo.setForeground(new Color(0,150,0));
            else if ( utils.verificarString(campo.getText()) && integerOstring)
                campo.setForeground(new Color(0,150,0));
            else
                campo.setForeground(Color.red);
        }

        public void focusLost(FocusEvent e) {
           campo.setForeground(Color.BLACK);
        }
    };
    
    
    public static void resaltadorJtextfield(final JTextField input){
    
          input.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                SwingUtilities.invokeLater( new Runnable() {

                                @Override
                                public void run() {
                                        input.selectAll();              
                                }
                        });
            }
        });
        
    }

}



 
